import 'package:file_preview/file_preview.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:get/get.dart';
import 'package:zootix/screens/chat/zt_file_preview.controller.dart';
import 'package:zootix/zt_app_theme.dart';

import '../../util/zt_util.dart';

class ZtPrivateMessageFilePreview extends StatelessWidget {
  final _controller =
      Get.put<ZtFilePreviewController>(ZtFilePreviewController());

  ZtPrivateMessageFilePreview({super.key, required filename, required url}) {
    _controller.filename = filename;
    _controller.url = url.replaceFirst('http://', 'https://');
    ;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: _buildBody(),
    );
  }

  Widget _buildBody() {
    return Stack(
      children: [
        Center(
          child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
            const Image(
                image: AssetImage('assets/images/file_picker_icon.png')),
            SizedBox(
              height: ZtScreenAdaper.height(10),
            ),
            Text(
              '${_controller.filename}',
              style: TextStyle(
                  color: Colors.black.withOpacity(0.4),
                  fontSize: ZtScreenAdaper.sp(15),
                  fontWeight: FontWeight.w500),
            )
          ]),
        ),
        Positioned(
            bottom: ZtScreenAdaper.height(100),
            left: 0,
            right: 0,
            child: Container(
                margin:
                    EdgeInsets.symmetric(horizontal: ZtScreenAdaper.width(50)),
                //在此设置
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(ZtScreenAdaper.sp(30)),
                  gradient: const LinearGradient(colors: [
                    Color.fromRGBO(175, 243, 32, 1),
                    Color.fromRGBO(171, 238, 28, 1),
                  ]),
                ),
                child: ElevatedButton(
                    style: ButtonStyle(
                      padding: MaterialStateProperty.all(EdgeInsets.symmetric(
                          horizontal: ZtScreenAdaper.width(25),
                          vertical: ZtScreenAdaper.height(8))),
                      elevation: MaterialStateProperty.all(0),
                      backgroundColor:
                          MaterialStateProperty.all(Colors.transparent),
                    ),
                    onPressed: _controller.previewFile,
                    child: Text(
                      'Open',
                      style: TextStyle(fontSize: ZtScreenAdaper.sp(20)),
                    ))))
      ],
    );
  }
}
